﻿@model LiteBlog.Models.PostCollectionModel
@using LiteBlog
@{
    this.ViewBag.Title = "Posts by Category - " + Model.FilterName;
    this.Layout = "~/Views/Shared/_SiteLayout.cshtml";
}

@section ScriptSection
{
    <script type="text/javascript">
        $(function () {
            var postsVm = new PostsVm();
            @if (Model.Author != null)
            {
            <text>var author = $.parseJSON('@Html.Json(Model.Author)');
            if (author) {
                postsVm.setAuthor(author.Name, author.Url);
            }
            </text>
            }
            postsVm.page(@Model.Page);
            postsVm.pageCount(@Model.PageCount);
            postsVm.url('@Url.Action("GetMore", "Category", new { id = Model.FilterId })');
            postsVm.loadJson(@Html.Json(Model.PostCollection));

            var pageElem = document.getElementById("page");
            ko.cleanNode(pageElem);
            ko.applyBindings(postsVm, pageElem);
        });
    </script>
}

<div class="content">
    <span class="caption">Category : @Model.FilterName</span>
</div>

<div id="posts" class="hidden" data-bind="css: { hidden: false }">
    <div data-bind="foreach: posts">
        @Html.Partial("PostControl")
    </div>
    <div class="pager" data-bind="click: getMore, visible: getMoreEnabled">
        More
    </div>
</div>


